package com.sl.au.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sl.au.entity.CustomerMailingInfo;
import com.sl.au.repository.CustomerMailingInfoRepository;
import com.sl.au.service.CustomerMailingInfoService;

@Service("CustomerMailingInfoService")
@Transactional
public class CustomerMailingInfoServiceImpl extends BaseServiceImpl implements CustomerMailingInfoService {
	@Autowired
	CustomerMailingInfoRepository customerMailingInfoRepository;
	@Override
	public CustomerMailingInfoRepository getCustomerMailingInfoRepository() {
		// TODO Auto-generated method stub
		return customerMailingInfoRepository;
	}

	@Override
	public List<CustomerMailingInfo> getMyPage(int start, int length, String CustomerId,String key) {
		Page<CustomerMailingInfo> pages=null;
		Pageable pageable=new PageRequest(start/length,length,Sort.Direction.DESC,"createTime");//排序
		pages=customerMailingInfoRepository.findAllTrance(CustomerId,key,pageable);
		// TODO Auto-generated method stub
		return pages.getContent();
	}

	@Override
	public long getMyPageCount(int start, int length, String CustomerId,String key) {
		// TODO Auto-generated method stub
		long pagesCount = 0;
		pagesCount = customerMailingInfoRepository.getCount(CustomerId,key);
		return pagesCount;
	}
}
